package sz.szsmk.citizencard.ui.fragment;

import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.provider.Settings;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.WindowManager;
import android.widget.CompoundButton;
import android.widget.HorizontalScrollView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.gyf.immersionbar.ImmersionBar;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnRefreshListener;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import sz.szsmk.citizencard.DaggerApplication;
import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.databinding.GoverActivityBinding;
import sz.szsmk.citizencard.gover.DefaultItemCallback;
import sz.szsmk.citizencard.gover.DefaultItemTouchHelper;
import sz.szsmk.citizencard.gover.FunctionAdapter;
import sz.szsmk.citizencard.gover.FunctionBlockAdapter;
import sz.szsmk.citizencard.gover.FunctionItem;
import sz.szsmk.citizencard.gover.SpaceItemDecoration;
import sz.szsmk.citizencard.ioc.Compontent.DaggerCommonFragmentComponent;
import sz.szsmk.citizencard.log.L;
import sz.szsmk.citizencard.model.network.bean.response.BaseBean;
import sz.szsmk.citizencard.model.network.bean.response.CloudFlashRes;
import sz.szsmk.citizencard.model.network.bean.response.GetOrderOpenidRes;
import sz.szsmk.citizencard.model.network.bean.response.QueryAllFunctionNewRes;
import sz.szsmk.citizencard.model.network.bean.response.SeleciUserAuthRes;
import sz.szsmk.citizencard.model.network.bean.response.VerifyBindNgUserRes;
import sz.szsmk.citizencard.model.network.dzbean.res.MessageEvent;
import sz.szsmk.citizencard.mvp.contract.IGoverContact;
import sz.szsmk.citizencard.mvp.presenter.APPHomePresenter;
import sz.szsmk.citizencard.mvp.presenter.GoverPresenter;
import sz.szsmk.citizencard.ui.activity.IMainActivity;
import sz.szsmk.citizencard.ui.activity.YouzanActivity;
import sz.szsmk.citizencard.ui.adapter.GoverHeadIconAdapter;
import sz.szsmk.citizencard.ui.base.IBaseFragment;
import sz.szsmk.citizencard.ui.dialogs.ServiceAuthDialog;
import sz.szsmk.citizencard.util.ACache;
import sz.szsmk.citizencard.util.Constant;
import sz.szsmk.citizencard.util.Density;
import sz.szsmk.citizencard.util.JumpThirdView;
import sz.szsmk.citizencard.util.JumpUtils;
import sz.szsmk.citizencard.util.StringUtils;
import sz.szsmk.citizencard.widget.StickyScrollView;

import static android.content.Context.NOTIFICATION_SERVICE;
import static sz.szsmk.citizencard.util.Constant.SZ_URL;

/**
 * Copyright (c)2018
 * author: zdh
 * created on: 2018/12/21 16:03
 * description:政务主页
 */
public class GoverFragment extends IBaseFragment<GoverPresenter, GoverActivityBinding>
        implements IGoverContact.IGoverView, View.OnClickListener {


    private HorizontalScrollView horizonLScrollView;
    private RecyclerView recyclerViewAll;
    private RecyclerView recyclerViewExist;
    private RadioGroup rg_tab;
    StickyScrollView scrolls;
    private ArrayList<String> mIdList = new ArrayList<>();
    private FunctionBlockAdapter blockAdapter;
    private FunctionAdapter functionAdapter;
    private GridLayoutManager gridManager;

    private List<String> scrollTab = new ArrayList<>();

    private int itemWidth = 0;
    private int lastRow = 0;
    private boolean isMove = false;//滑动状态
    private int scrollPosition = 0;
    private String currentTab;//当前的标签
    private int tabWidth = 0;//标签宽度

    private String funString = "";
    private List<FunctionItem> allData;
    private List<FunctionItem> selData;
    List<FunctionItem> tabs;
    private static final int MAX_COUNT = 14;
    private boolean isDrag = false;
    private RecyclerView goverHeadRv;
    private TextView goverHeadEditTv;
    private TextView goverHeadDesTv;
    private QueryAllFunctionNewRes.ClassListBean headList;
    private QueryAllFunctionNewRes.ClassListBean goverList;
    private QueryAllFunctionNewRes.ClassListBean huiminList;
    private QueryAllFunctionNewRes.ClassListBean bianminList;
    private GoverHeadIconAdapter headIconAdapter;
    private List<QueryAllFunctionNewRes.ClassListBean> class_list1 = new ArrayList<>();
    private ArrayList<String> idList = new ArrayList<>();
    private String murl;
    private List<String> fiveheadList = new ArrayList<>();
    public static GoverFragment getInstance() {
        GoverFragment goverFragment = new GoverFragment();
        return goverFragment;
    }

    @Override
    protected int attachLayoutRes() {
        return R.layout.gover_activity;
    }

    @Override
    protected void initInjector() {
        DaggerCommonFragmentComponent.builder().appCompontent(DaggerApplication.getAppComponent())
                .build().inject(this);
    }

    @Override
    public void onResume() {
        super.onResume();
        String access_token = ACache.get(mContext).getAsString("access_token");
        if (access_token != null) {
            mPresenter.getGetOrderIdForGHF("", "");
        }

    }

    @Override
    protected void initViews() {
        //MainActivity沉浸  手动改变view的高度  便于 滑动整体 标题栏变色
        ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) dataBinding.titleLayout.vStatusBar.getLayoutParams();
        layoutParams.height = ImmersionBar.getStatusBarHeight(requireActivity());
        dataBinding.titleLayout.vStatusBar.setLayoutParams(layoutParams);
        dataBinding.titleLayout.vStatusBar.setBackgroundColor(ContextCompat.getColor(requireContext(),R.color.color_2184FA));


        horizonLScrollView = dataBinding.horizonLScrollView;
        recyclerViewAll = dataBinding.recyclerViewAll;
        recyclerViewExist = dataBinding.recyclerViewExist;
        scrolls =dataBinding.scrolls;
        mPresenter.getViewData();


        rg_tab = dataBinding.rgTab;
        dataBinding.goverOverTv.setVisibility(View.GONE);
        dataBinding.recyclerViewExist.setVisibility(View.GONE);
        headListent();
        init();
        addListener();
        reduceListener();
        dataBinding.titleLayout.back.setVisibility(View.GONE);
        dataBinding.titleLayout.settingTitle.setOnClickListener(this);
        dataBinding.titleLayout.bjTv.setOnClickListener(this);
        dataBinding.titleLayout.settingTitle.setText(getActivity().getResources().getString(R.string.serivce));
        dataBinding.titleLayout.settingTitle.setOnClickListener(this);
        dataBinding.titleLayout.bjTv.setVisibility(View.VISIBLE);
        dataBinding.titleLayout.bjTv.setText(getActivity().getResources().getString(R.string.edit));
        dataBinding.titleLayout.bjTv.setTextColor(getActivity().getResources().getColor(R.color.white));
        ViewTreeObserver observer = scrolls.getViewTreeObserver();
        observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
            public boolean onPreDraw() {
                if (!isMeasured) {
                    int layoutHeight = scrolls.getTop();
                    Log.d("height","------------>"+layoutHeight);
                    isMeasured = true;
                }
                return true;
            }
        });
        dataBinding.goverSmartLayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                mPresenter.getViewData();
            }
        });
        dataBinding.goverSmartLayout.setEnableLoadMore(false);


         //首页点击更多之后进入页面进行编辑
//        Bundle bundle=this.getArguments();
//        if(bundle!=null&&bundle.getString("data").equals("changeAll")){
//        //    dataBinding.titleLayout.bjTv.performClick();
////            dataBinding.editViewLayout.setVisibility(View.VISIBLE);
////            recyclerViewExist.setVisibility(View.VISIBLE);
////            for (int i = 0; i < allData.size(); i++) {
////                FunctionItem functionItem = allData.get(i);
//////                    functionItem.setSelect(false);
////                functionItem.setClick(false);
////                functionAdapter.notifyDataSetChanged();
////            }
////            dataBinding.goverOverTv.setVisibility(View.VISIBLE);
////            dataBinding.goverHeadRl.setVisibility(View.GONE);
////            dataBinding.goverCancelTv.setVisibility(View.VISIBLE);
////            dataBinding.goverZwTv.setVisibility(View.GONE);
//
//        }

        checkNotify();
    }

    private boolean isMeasured;
    private void headListent() {

        goverHeadRv = dataBinding.goverHeadRv;
        goverHeadEditTv = dataBinding.goverHeadEditTv;
        goverHeadDesTv = dataBinding.goverHeadDesTv;
        goverHeadEditTv.setOnClickListener(this);
        dataBinding.goverOverTv.setOnClickListener(this);
        dataBinding.goverCancelTv.setOnClickListener(this);
        LinearLayoutManager manager = new LinearLayoutManager(getActivity());
        manager.setOrientation(LinearLayoutManager.HORIZONTAL);
        goverHeadRv.setLayoutManager(manager);
        headIconAdapter = new GoverHeadIconAdapter(getActivity());
        goverHeadRv.setAdapter(headIconAdapter);
    }

    private void init() {
        allData = new ArrayList<>();
        selData = new ArrayList<>();
        tabs = new ArrayList<>();
        blockAdapter = new FunctionBlockAdapter(getActivity(), selData);
        recyclerViewExist.setLayoutManager(new GridLayoutManager(getActivity(), 4));
        recyclerViewExist.setAdapter(blockAdapter);
        recyclerViewExist.addItemDecoration(new SpaceItemDecoration(4, dip2px(getActivity(), 10)));

        DefaultItemCallback callback = new DefaultItemCallback(blockAdapter);
        DefaultItemTouchHelper helper = new DefaultItemTouchHelper(callback);
        helper.attachToRecyclerView(recyclerViewExist);

        gridManager = new GridLayoutManager(getActivity(), 4) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        };
        gridManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
                FunctionItem fi = allData.get(position);
                return fi.isTitle ? 4 : 1;
            }
        });

        functionAdapter = new FunctionAdapter(getActivity(), allData);
        recyclerViewAll.setLayoutManager(gridManager);
        recyclerViewAll.setAdapter(functionAdapter);
        SpaceItemDecoration spaceDecoration = new SpaceItemDecoration(4, dip2px(getActivity(), 10));
        recyclerViewAll.addItemDecoration(spaceDecoration);
        itemWidth = getAtyWidth(getActivity()) / 4 + dip2px(getActivity(), 2);

        resetEditHeight(selData.size());

        functionAdapter.GhfOnClick(new FunctionAdapter.GhfInterface() {
            @Override
            public void onClick(View view, FunctionItem data, int position, boolean isClick) {
                //埋点
                mPresenter.userBehaviorBrowse(data.getModularId());
                if (isClick && !TextUtils.isEmpty(data.getLink_url())) {
                    String link_url = data.getLink_url();
                    Log.i("服务info",data.getName()+"   "+data.getLink_url()+"   "+data.getSys_label());
                    if (data.getName().equals("市民商城")){
                        link_url="https://xfzc.gusu.gov.cn/orderfood/index.html";
                    }else if (data.getName().equals("桂花分")){

                    }
                    String sys_label=data.getSys_label();
                    //最上层判断登录与否，没有的话跳转到登录页面， 与图表内部点击判断可能会重复

                    if (link_url.equals("proto:fund")) {
                        String access_token = ACache.get(mContext).getAsString("access_token");
                        if (access_token == null) {
                            JumpUtils.jump(mContext, "login", 0);
                        }
                        mPresenter.selectUserAuth("gjj",data);
                    } else if (link_url.equals("proto:social")) {
                        String access_token = ACache.get(mContext).getAsString("access_token");
                        if (access_token == null) {
                            JumpUtils.jump(mContext, "login", 0);
                        }
                        mPresenter.selectUserAuth("sb",data);
                    } else if (link_url.equals("proto:osmanthus")) {
                        String access_token = ACache.get(mContext).getAsString("access_token");
                        if (access_token == null) {
                            JumpUtils.jump(mContext, "login", 0);
                        }
                        mPresenter.selectUserAuth("ghf",data);
                    } else if (link_url.equals("proto:finance")){
//                        MessageEvent message = new MessageEvent(MessageEvent.CODE_OPENNG);
//                        EventBus.getDefault().post(message);
//                        JumpThirdView.baseToJumpView(activity, url, syslabl, need_header, "")
                        JumpThirdView.baseToJumpView(requireContext(), data.getLink_url(), data.getSys_label(), data.getNeed_header(), "");
                    }  else {
                        if(!StringUtils.isEmpty(sys_label)&&sys_label.equals("FINANCE")){
                            JumpThirdView.baseToJumpView(getActivity(), data.getLink_url(), data.getSys_label(), data.getNeed_header(), "");
                        }else{
                            if (data.getName().equals("教育E卡通"))
                                JumpThirdView.baseToJumpView(getActivity(), data.getLink_url(), null, data.getNeed_header(), "");
                            else
                                JumpThirdView.baseToJumpView(getActivity(), data.getLink_url(), data.getSys_label(), data.getNeed_header(), "");
                            return;
                        }



                    }
                }

            }
        });
    }
    //目标项是否在最后一个可见项之后
    private boolean mShouldScroll;
    //记录目标项位置
    private int mToPosition;

    /**
     * 滑动到指定位置
     */
    private void smoothMoveToPosition(RecyclerView mRecyclerView, final int position) {
        // 第一个可见位置
        int firstItem = mRecyclerView.getChildLayoutPosition(mRecyclerView.getChildAt(0));
        // 最后一个可见位置
        int lastItem = mRecyclerView.getChildLayoutPosition(mRecyclerView.getChildAt(mRecyclerView.getChildCount() - 1));
        if (position < firstItem) {
            // 第一种可能:跳转位置在第一个可见位置之前，使用smoothScrollToPosition
            mRecyclerView.smoothScrollToPosition(position);
            int top = mRecyclerView.getChildAt(position).getTop();
            scrolls.smoothScrollBy(0, top);
        } else if (position <= lastItem) {
            // 第二种可能:跳转位置在第一个可见位置之后，最后一个可见项之前
            int movePosition = position - firstItem;
            if (movePosition >= 0 && movePosition < mRecyclerView.getChildCount()) {

            }
        } else {
            // 第三种可能:跳转位置在最后可见项之后，则先调用smoothScrollToPosition将要跳转的位置滚动到可见位置
            // 再通过onScrollStateChanged控制再次调用smoothMoveToPosition，执行上一个判断中的方法
            mRecyclerView.smoothScrollToPosition(position);
            mToPosition = position;
            mShouldScroll = true;
        }
    }
    @Override
    protected void updateViews() {

    }


    public void toJumpView(Context mContext, String url, String sys_label, int need_header, FunctionItem data) {

        if (url == null) {
            return;
        }
        String access_token = ACache.get(mContext).getAsString("access_token");
        if (access_token == null) {
            JumpUtils.jump(mContext, "login", 0);
        } else {

            if (url.equals("citizenCard")) {
                ((IMainActivity) mContext).getmPresenter().getOpenId();
            } else if (url.equals("proto:bus")) {
                JumpUtils.jump(mContext, "BusHomeActivity", 0);

            } else if (url.equals("proto:add_cards")) {

//            mPresenter.queryCitizenCard();
                ((IMainActivity) getActivity()).queryUserCard("gover");
            } else if (url.equals("proto:fund")) {
                //公积金
                mPresenter.selectUserAuth("gjj",data);
            } else if (url.contains("youzan")) {
                ACache.get(DaggerApplication.getIns()).remove("sykt");
                ACache.get(DaggerApplication.getIns()).put("sykt", "sykt");

                Intent intent = new Intent(mContext, YouzanActivity.class);
                intent.putExtra(YouzanActivity.KEY_URL, url);
                mContext.startActivity(intent);
            } else if (url.equals("proto:social")) {
//                Toast.makeText(mContext, "社保", Toast.LENGTH_SHORT).show();

                mPresenter.selectUserAuth("sb",data);

            } else if (url.equals("proto:osmanthus")) {
                String ghfAuth = Constant.GHF_AUTH;
                //0未授权，1已授权，2未实名(L3认证)
                if (ghfAuth.equals("2")) {
                    Bundle bundle = new Bundle();
                    bundle.putInt("intotype", 1);
                    bundle.putString("choosetype", "ghf");
                    JumpUtils.jumptoNatvie(mContext, "RealNameActivity", 0, bundle);
                } else if (ghfAuth.equals("1")) {

                    String url1 = SZ_URL + Constant.EXTENT;
                    Bundle bundle = new Bundle();
                    bundle.putString("url", url1);
                    bundle.putString(Constant.TITLE, "桂花分");
                    JumpUtils.jumptoNatvie(mContext, "webView", 0, bundle);

                } else if (ghfAuth.equals("0")) {
                    String murl = SZ_URL + Constant.EXTENT;
                    Bundle bundle = new Bundle();
                    bundle.putString("url", murl);
                    bundle.putString(Constant.TITLE, "桂花分");
                    JumpUtils.jumptoNatvie(mContext, "webView", 0, bundle);
                }
            } else if (url.equals("proto:subway")) {
                JumpUtils.jump(mContext, "SubwayHomeActivity", 0);

            } else if (url.equals("proto:balance_inquiry")) {
                //余额查询
                JumpUtils.jump(mContext, "querybalance", 0);
            } else if (url.equals("proto:service_network")) {
                //服务网点
                JumpUtils.jump(mContext, "nerwork", 0);

            } else if (url.equals("proto:citizenCard_charge")) {
                //云闪充
                mPresenter.checkSuccessOrderStatus();

            } else if (url.equals("proto:consumer_business")) {
                //消费商家
                JumpUtils.jump(mContext, "business", 0);
            }  else {
//            String access_token = ACache.get(mContext).getAsString("access_token");
                if (access_token == null) {
                    Toast.makeText(mContext, "请登录", Toast.LENGTH_SHORT).show();
                } else {
                    /**
                     * sys_label参数判断逻辑
                     * 1.sys_label为null  或者sys_label 为"";不用管 直接跳转
                     * 2.sys_label为NOHEADER 拼接access_token
                     * 3.sys_label不为空，且不为NOHEADER，调张旺接口
                     */
                    L.e(Constant.TITLE, "url--" + url + "----syslabel---" + sys_label);
                    if (url == null || url.trim().equals("")) {
                        return;
                    }
                    Bundle bundle = new Bundle();
//                            int need_header = bean.getNeed_header();
                    if (need_header == 1) {
                        bundle.putString(Constant.TITLE, "");
                    }
                    if (sys_label != null && sys_label.equals("NOHEADER")) {

                        bundle.putString("url", url + "?access_token=" + access_token);
                        JumpUtils.jumptoNatvie(mContext, "webView", 0, bundle);
                    } else if (sys_label != null && sys_label.equals("HUIMIN")) {
                        bundle.putString("stt", "stt");

                        String extent = Constant.EXTENT;
                        if (url.contains("?")) {
                            murl = url + "&" + Constant.EXTENT;
                        } else {
                            murl = url + "?" + Constant.EXTENT;
                        }
                        bundle.putString("url", murl);

                        JumpUtils.jumptoNatvie(mContext, "webView", 0, bundle);
                    } else if (sys_label != null && sys_label.equals("ZZK")) {
                        bundle.putString("url", url + "?access_token=" + access_token);
//                        JumpUtils.jumptoNatvie(mContext, "webView", 0, bundle);
                        JumpUtils.jumptoNatvie(mContext, "webView", 0, bundle);
                    }else if (sys_label != null && sys_label.equals("GUIHUAFEN")) {
                        bundle.putString("stt", "stt");
                        if (url.contains("?")) {
                            murl = url + "&" + Constant.EXTENT_GHF;
                        } else {
                            murl = url + "?" + Constant.EXTENT_GHF;
                        }
                        bundle.putString("url", murl);
                        JumpUtils.jumptoNatvie(mContext, "webView", 0, bundle);
                    } else if (sys_label != null && sys_label.length() == 0) {
                        bundle.putString("url", url);
                        JumpUtils.jumptoNatvie(mContext, "webView", 0, bundle);
                    } else if (sys_label == null) {
                        bundle.putString("url", url);
                        if (url.contains("youzan")) {
                            bundle.putString(Constant.TITLE, "");
                        }
                        JumpUtils.jumptoNatvie(mContext, "webView", 0, bundle);
                    }else{
                        mPresenter.getGetOrderIdForNGBOSS(url,sys_label,data);
                    }
                }

            }
        }


    }

    private boolean defaultselect;

    @Override
    public void getViewDataSucc(QueryAllFunctionNewRes response) {
        dataBinding.goverSmartLayout.finishRefresh();
        allData.clear();
        class_list1 = response.getClass_list();

//        QueryAllFunctionNewRes.ClassListBean classListBean = class_list1.get(1);
        idList.clear();
        selData.clear();
        QueryAllFunctionNewRes.ClassListBean mBean = class_list1.get(0);
        List<QueryAllFunctionNewRes.ClassListBean.FunctionListBean> functionList = mBean.getFunction_list();
        for (int i = 0; i < mBean.getFunction_list().size(); i++) {
            QueryAllFunctionNewRes.ClassListBean.FunctionListBean bean = functionList.get(i);
            FunctionItem item = new FunctionItem(bean.getFunction_name(), true,
                    mBean.getFunction_list().size(),
                    bean.getIcon_url(),
                    bean.getLink_url());
            item.setModularId(bean.getModularId());
            item.setSelect(true);
            selData.add(item);
        }
        blockAdapter.setViewData(selData);
        resetEditHeight(selData.size());
        blockAdapter.notifyDataSetChanged();
        tabs.clear();
        for (int i = 0; i < class_list1.size(); i++) {
            if (i != 0) {
                QueryAllFunctionNewRes.ClassListBean bean = class_list1.get(i);
                List<QueryAllFunctionNewRes.ClassListBean.FunctionListBean> function_list = bean.getFunction_list();
                for (int j = 0; j < function_list.size(); j++) {

                    int function_id = function_list.get(j).getFunction_id();
                    idList.add(function_id + "");
                }
                FunctionItem item = new FunctionItem(bean.getClass_name(), true, bean.getFunction_list().size());


                allData.add(item);
                tabs.add(item);
                for (int j = 0; j < bean.getFunction_list().size(); j++) {
                    for (int k = 0; k < selData.size(); k++) {
                        defaultselect = false;
                        if (selData.get(k).getName().equals(bean.getFunction_list().get(j).getFunction_name())) {
                            defaultselect = true;
                            break;
                        }
                    }
                    QueryAllFunctionNewRes.ClassListBean.FunctionListBean childBean = bean.getFunction_list().get(j);
                    FunctionItem childItem = new FunctionItem(childBean.getFunction_name(), defaultselect, childBean.getIcon_url(), idList.get(j) + "",
                            childBean.getLink_url(), childBean.getSys_label(), childBean.getNeed_header());
                    childItem.setModularId(childBean.getModularId());
                    allData.add(childItem);
                }
            }
        }
        //我的应用
        List<QueryAllFunctionNewRes.ClassListBean.FunctionListBean> headList = class_list1.get(0).getFunction_list();
        headIconAdapter.setViewData(headList);
        headIconAdapter.notifyDataSetChanged();

        for (int i = 0; i < 5; i++) {
            fiveheadList.add(headList.get(i).getFunction_name());
        }
        initTab();
        for (int m = 0; m < allData.size(); m++) {
            FunctionItem functionItem = allData.get(m);//这明显没作用
            allData.get(m).setClick(true);
            functionAdapter.notifyDataSetChanged();
        }

        String name = allData.get(1).getName();
        String class_id = allData.get(1).background;
        L.e(Constant.TAG, "传入的id" + name + class_id);
        functionAdapter.setViewData(allData);
        functionAdapter.notifyDataSetChanged();
        StringBuffer buffer=new StringBuffer();
        for(int i=0;i<5;i++){
            buffer.append(allData.get(i).getName()+"-");
            ACache.get(getActivity()).put("fiveFun",buffer.toString());
        }


    }

    @Override
    public void getViewDataFail(QueryAllFunctionNewRes response) {
        dataBinding.goverSmartLayout.finishRefresh();
    }

    @Override
    public void changeUserFuncFail(BaseBean response) {
        Toast.makeText(mActivity, response.getMessage(), Toast.LENGTH_SHORT).show();
    }

    @Override
    public void changeUserFuncSucc() {
        mPresenter.getViewData();
    }

    @Override
    public void selectUserAuthFail() {

    }

    @Override
    public void selectUserAuthSucc(SeleciUserAuthRes response, String type, FunctionItem data) {
        String access_token = ACache.get(getActivity()).getAsString("access_token");
        List<SeleciUserAuthRes.AuthTypeListBean> authTypeList = response.getAuthTypeList();

        if (type.equals("gjj")) {
            String isAuth = authTypeList.get(1).getIsAuth();
            //0未授权，1已授权，2未实名(L3认证)
            if (isAuth.equals("2")) {
                Bundle bundle = new Bundle();
                bundle.putInt("intotype", 1);
                bundle.putString("choosetype", "gjj");
                JumpUtils.jumptoNatvie(getActivity(), "RealNameActivity", 0, bundle);
            } else if (isAuth.equals("1")) {
                Bundle bundle = new Bundle();
                String path = Constant.BASE_URL + "app-front-end/#/fund/main?access_token=" + access_token;
                bundle.putString("url", path);
                bundle.putString(Constant.CUST_NAME, Constant.ID_NAME);
                JumpUtils.jumptoNatvie(mContext, "webView", 0, bundle);
            } else if (isAuth.equals("0")) {
                String url =Constant.BASE_URL + "app-front-end/#/fund/main?access_token=" + access_token;
                Bundle bundle = new Bundle();
                bundle.putString("url", url);
                JumpUtils.jumptoNatvie(getActivity(), "webView", 0, bundle);
            }
        }

        if (type.equals("sb")) {
            String isAuth = authTypeList.get(0).getIsAuth();
            //0未授权，1已授权，2未实名(L3认证)
            if (isAuth.equals("2")) {
                Bundle bundle = new Bundle();
                bundle.putInt("intotype", 1);
                bundle.putString("choosetype", "sb");
                JumpUtils.jumptoNatvie(getActivity(), "RealNameActivity", 0, bundle);
            } else if (isAuth.equals("1")) {
                Bundle bundle = new Bundle();
                String path = Constant.BASE_URL + "app-front-end/#/social/main?access_token=" + access_token;
                bundle.putString("url", path);
                JumpUtils.jumptoNatvie(mContext, "webView", 0, bundle);
            } else if (isAuth.equals("0")) {
                String url = Constant.BASE_URL + "app-front-end/#/fundAndSociety/authPage?access_token=" + access_token + "&type=1&name=" + Constant.ID_NAME;
                Bundle bundle = new Bundle();
                bundle.putString("url", url);
                JumpUtils.jumptoNatvie(getActivity(), "webView", 0, bundle);
            }
        }
        if (type.equals("ghf")) {
            String isAuth = authTypeList.get(2).getIsAuth();
            //0未授权 直接跳 他们网页，1已授权，2未实名(L3认证)
            if (isAuth.equals("0")|| isAuth.equals("1")) {

                Bundle bundle = new Bundle();
                //跳转桂花分
                String murl = SZ_URL+"?" + Constant.EXTENT_GHF;
                bundle.putString("url", murl);
                bundle.putString(Constant.TITLE, "桂花分");
                JumpUtils.jumptoNatvie(mContext, "webView", 0, bundle);

            } else if (isAuth.equals("2")) {
                Bundle bundle = new Bundle();
                bundle.putInt("intotype", 1);
                bundle.putString("choosetype", "ghf");
                JumpUtils.jumptoNatvie(getActivity(), "RealNameActivity", 0, bundle);
            }

        }

    }

    @Override
    public void checkSuccessOrderStatusFail(CloudFlashRes cloudFlashRes) {

    }

    @Override
    public void checkSuccessOrderStatusSucc(String orderStatus) {
        String access_token = ACache.get(mContext).getAsString("access_token");
        if (orderStatus != null) {
            if (orderStatus.equals("1")) {
                Bundle bundle = new Bundle();
                bundle.putString("url", Constant.BASE_URL + "app-front-end/#/charge/main?access_token=" + access_token);
                JumpUtils.jumptoNatvie(mContext, "webView", 0, bundle);
            } else if (orderStatus.equals("0")) {
                Bundle bundle = new Bundle();
                bundle.putString("url", Constant.BASE_URL + "app-front-end/#/charge/guide?access_token=" + access_token);
                JumpUtils.jumptoNatvie(mContext, "webView", 0, bundle);
            }
        }
    }

    @Override
    public void getGetOrderIdFail() {

    }

    @Override
    public void getGetOrderIdSucc(GetOrderOpenidRes response, String type, String url, FunctionItem data) {

    }

    @Override
    public void getGetOrderIdForNGBOSSResult(GetOrderOpenidRes response, String type, String url, FunctionItem data) {
        Bundle bundle = new Bundle();
        bundle.putString("url", url+"?"+response.getExtend());
        JumpUtils.jumptoNatvie(mContext, "webView", 0, bundle);
    }

    @Override
    public void getGetOrderIdForGHFResult(GetOrderOpenidRes response, String type, String url) {

    }

    @Override
    public void verifyBindNgUserSucc(VerifyBindNgUserRes verifyBindNgUserRes) {
        //        true: 已经绑定授权过
//        false: 需要用户确认是否授权
        if(verifyBindNgUserRes.isHasBindNgUser()==true){
            Bundle bundle = new Bundle();
            String nGaccess_token = verifyBindNgUserRes.getNgAccessToken();
            bundle.putString("url", Constant.NGfinance + nGaccess_token);
            JumpUtils.jumptoNatvie( getContext(), "webView", 0, bundle);
        }else{
            ServiceAuthDialog serviceAuthDialog = new ServiceAuthDialog(getContext());
            serviceAuthDialog.setiServiceAuthDialog(new ServiceAuthDialog.IServiceAuthDialog() {
                @Override
                public void onclick() {
                    mPresenter.toBindNgUser();
                }
            });
            serviceAuthDialog.show();
        }
    }

    @Override
    public void toBindNgUserSucc(VerifyBindNgUserRes verifyBindNgUserRes) {
        Bundle bundle = new Bundle();
        String nGaccess_token = verifyBindNgUserRes.getNgAccessToken();
        bundle.putString("url", Constant.NGfinance + nGaccess_token);
        JumpUtils.jumptoNatvie( getContext(), "webView", 0, bundle);
    }

    @Override
    public void toRedirectNgUrlSucc(VerifyBindNgUserRes verifyBindNgUserRes) {
        if(!TextUtils.isEmpty(verifyBindNgUserRes.getUrl())){
            Bundle bundle = new Bundle();
            bundle.putString("url", verifyBindNgUserRes.getUrl());
            JumpUtils.jumptoNatvie(mContext, "webView", 0, bundle);
        }
    }

    public void addListener() {
        functionAdapter.setOnItemAddListener(new FunctionAdapter.OnItemAddListener() {
            @Override
            public boolean add(FunctionItem item) {
                if (selData != null && selData.size() < MAX_COUNT) {   // 更新选择列表，所有列表已在内部进行更新
                    try {
//                        Toast.makeText(mActivity, "----" + item.getImageUrl(), Toast.LENGTH_SHORT).show();
                        FunctionItem item1 = new FunctionItem(item.name, true,
                                1,
                                item.getImageUrl(),
                                item.class_id);
                        selData.add(item1);
                        for (int i = 0; i < selData.size(); i++) {
                            L.e(Constant.TAG, "-----------------" + selData.get(i).background);
                        }

                        resetEditHeight(selData.size());
                        blockAdapter.notifyDataSetChanged();
                        item.isSelect = true;
                        return true;
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    return false;
                } else {
                    Toast.makeText(getActivity(), "选中的模块不能超过" + MAX_COUNT + "个", Toast.LENGTH_SHORT).show();
                    return false;
                }
            }
        });

        blockAdapter.setOnItemRemoveListener(new FunctionBlockAdapter.OnItemRemoveListener() {
            @Override
            public void remove(FunctionItem item) {
                // 更新所有列表，选择列表已在内部进行更新
                try {
                    if (item != null && item.name != null) {
                        for (int i = 0; i < allData.size(); i++) {
                            FunctionItem data = allData.get(i);
                            if (data != null && data.name != null) {
                                if (item.name.equals(data.name)) {
                                    data.isSelect = false;
                                    break;
                                }
                            }
                        }
                        functionAdapter.notifyDataSetChanged();
                    }
                    resetEditHeight(selData.size());
                } catch (Exception e) {
                    e.printStackTrace();
                }

            }
        });
//        recyclerViewAll.addOnScrollListener(onScrollListener);
    }


    public void reduceListener() {
        functionAdapter.setOnItemReduceListener(new FunctionAdapter.OnItemReduceListener() {
            @Override
            public boolean reduce(FunctionItem item) {
                if (selData != null && selData.size() > 0) {   // 更新选择列表，所有列表已在内部进行更新
                    try {
//                        Toast.makeText(mActivity, "----" + item.getImageUrl(), Toast.LENGTH_SHORT).show();
//                        selData.add(item1);
//                        selData.remove(item);

                        Iterator<FunctionItem> it = selData.iterator();
                        while (it.hasNext()) {
                            FunctionItem tempitem = it.next();
                            if (tempitem.getName().equals(item.getName())) {
                                it.remove();
                            }

                        }
                        for (int i = 0; i < selData.size(); i++) {
                            L.e(Constant.TAG, "-----------------" + selData.get(i).background);
                        }

                        resetEditHeight(selData.size());
                        blockAdapter.notifyDataSetChanged();
                        item.isSelect = false;
                        return true;
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    return false;
                } else {
                    return false;
                }
            }
        });

        blockAdapter.setOnItemRemoveListener(new FunctionBlockAdapter.OnItemRemoveListener() {
            @Override
            public void remove(FunctionItem item) {
                // 更新所有列表，选择列表已在内部进行更新
                try {
                    if (item != null && item.name != null) {
                        for (int i = 0; i < allData.size(); i++) {
                            FunctionItem data = allData.get(i);
                            if (data != null && data.name != null) {
                                if (item.name.equals(data.name)) {
                                    data.isSelect = false;
                                    break;
                                }
                            }
                        }
                        functionAdapter.notifyDataSetChanged();
                    }
                    resetEditHeight(selData.size());
                } catch (Exception e) {
                    e.printStackTrace();
                }

            }
        });
//        recyclerViewAll.addOnScrollListener(onScrollListener);
    }

    private RecyclerView.OnScrollListener onScrollListener = new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
            try {
                if (isMove && newState == RecyclerView.SCROLL_STATE_IDLE) {
                    isMove = false;
                    View view = gridManager.findViewByPosition(scrollPosition);
                    if (view != null) {
                        int top = (int) view.getTop();
                        recyclerView.scrollBy(0, top);
                    }
                }
                if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
                    isDrag = true;
                } else {
                    isDrag = false;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

        }

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            if (isDrag) {  //拖动过程中
                int position = gridManager.findFirstVisibleItemPosition();
                if (position > 0) {
                    for (int i = 0; i < position + 1; i++) {
                        if (allData.get(i).isTitle) {
                            currentTab = allData.get(i).name;
                        }
                    }
                    scrollTab(currentTab);
                }
            }
        }
    };

    public int getAtyWidth(Context context) {
        try {
            DisplayMetrics mDm = new DisplayMetrics();
            ((Activity) context).getWindowManager().getDefaultDisplay()
                    .getMetrics(mDm);
            return mDm.widthPixels;
        } catch (Exception e) {
            return 0;
        }
    }


    private CompoundButton.OnCheckedChangeListener onCheckedChangeListener = new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            try {
                int position = (int) buttonView.getTag();
//                String text = buttonView.getText().toString();
//                if (!currentTab.equals(text) && isChecked) {
//                    currentTab = text;
//                    moveToPosition(position);
//                }
//                scrolls.post(new Runnable() {
//                    @Override
//                    public void run() {
//                        if(isChecked){
//                            int top = recyclerViewAll.getChildAt(position).getTop();
//                            Log.d("recytop","------------->"+top);
//                            if(top<0){
//                                scrolls.scrollTo(0, top);
//                            }else{
//                                int trueTop = top-20;
//                                scrolls.smoothScrollTo(0, trueTop);
//                            }
//                        }
//
//                    }
//                });
            } catch (Exception e) {
                e.printStackTrace();
            }

        }
    };

    private void moveToPosition(int position) {
        int first = gridManager.findFirstVisibleItemPosition();
        int end = gridManager.findLastVisibleItemPosition();
        if (first == -1 || end == -1)
            return;
        if (position <= first) {      //移动到前面
            gridManager.scrollToPosition(position);
        } else if (position >= end) {      //移动到后面
            isMove = true;
            scrollPosition = position;
            gridManager.smoothScrollToPosition(recyclerViewAll, null, position);
        } else {//中间部分
            int n = position - gridManager.findFirstVisibleItemPosition();
            if (n > 0 && n < allData.size()) {
                int top = gridManager.findViewByPosition(position).getTop();
                recyclerViewAll.scrollBy(0, top);
            }
        }
    }


    private void resetEditHeight(int size) {
        try {
            if (size == 0) {
                size = 1;
            }
            int row = size / 4 + (size % 4 > 0 ? 1 : 0);
            if (row <= 0)
                row = 1;
            if (lastRow != row) {
                lastRow = row;
                ViewGroup.LayoutParams params = recyclerViewExist.getLayoutParams();
                params.height = itemWidth * row;
                recyclerViewExist.setLayoutParams(params);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }


    private void initTab() {
        rg_tab.removeAllViews();
        WindowManager wm1 = getActivity().getWindowManager();
        int screenwidth = wm1.getDefaultDisplay().getWidth() - Density.dip2px(getActivity(), 40);
        try {
            if (tabs != null && tabs.size() > 0) {
                currentTab = tabs.get(0).name;
                int padding = dip2px(getActivity(), 10);
                int size = tabs.size();
                for (int i = 0; i < size; i++) {
                    FunctionItem item = tabs.get(i);
                    if (item.isTitle) {
                        scrollTab.add(item.name);
                        RadioButton rb = new RadioButton(getActivity());
                        rb.setPadding(padding, 0, padding, 0);
                        rb.setButtonDrawable(null);
                        rb.setGravity(Gravity.CENTER);
                        rb.setText(item.name);
                        rb.setTag(item.subItemCount);
                        rb.setWidth(screenwidth / 3);
                        rb.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
                        try {
                            rb.setTextColor(getResources().getColorStateList(R.color.color_3d494f));
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        rb.setCompoundDrawablesWithIntrinsicBounds(null, null, null, getResources().getDrawable(R.drawable.bg_block_tab));
                        rb.setOnCheckedChangeListener(onCheckedChangeListener);
                        rg_tab.addView(rb);
                    }
                }
                ((RadioButton) rg_tab.getChildAt(0)).setChecked(true);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private int getTabWidth() {
        if (tabWidth == 0) {
            if (rg_tab != null && rg_tab.getChildCount() != 0) {
                tabWidth = rg_tab.getWidth() / rg_tab.getChildCount();
            }
        }
        return tabWidth;
    }

    public int dip2px(Context context, float dpValue) {
        float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale + 0.5f);
    }

    private void scrollTab(String newTab) {
        try {
            int position = scrollTab.indexOf(currentTab);
            int targetPosition = scrollTab.indexOf(newTab);
            currentTab = newTab;
            if (targetPosition != -1) {
                int x = (targetPosition - position) * getTabWidth();
                RadioButton radioButton = ((RadioButton) rg_tab.getChildAt(targetPosition));
                radioButton.setOnCheckedChangeListener(null);
                radioButton.setChecked(true);
                radioButton.setOnCheckedChangeListener(onCheckedChangeListener);
                horizonLScrollView.scrollBy(x, 0);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static ArrayList<String> removeDuplicate(ArrayList<String> list) {
        for (int i = 0; i < list.size() - 1; i++) {
            for (int j = list.size() - 1; j > i; j--) {
                if (list.get(j).equals(list.get(i))) {
                    list.remove(j);
                }
            }
        }
        return list;
    }



    private void checkNotify(){
        NotificationManagerCompat notification = NotificationManagerCompat.from(getActivity());
        boolean isEnabled = notification.areNotificationsEnabled();

        if (!isEnabled) {
            //未打开通知
            AlertDialog alertDialog = new AlertDialog.Builder(getActivity())
                    .setTitle("提示")
                    .setMessage("请在“通知”中打开通知权限")
                    .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();
                        }
                    })
                    .setPositiveButton("去设置", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();
                            Intent intent = new Intent();
                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                                intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");
                                intent.putExtra("android.provider.extra.APP_PACKAGE", getActivity().getPackageName());
                            } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {  //5.0
                                intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");
                                intent.putExtra("app_package", getActivity().getPackageName());
                                intent.putExtra("app_uid", getActivity().getApplicationInfo().uid);
                                startActivity(intent);
                            } else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {  //4.4
                                intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                                intent.addCategory(Intent.CATEGORY_DEFAULT);
                                intent.setData(Uri.parse("package:" + getActivity().getPackageName()));
                            } else if (Build.VERSION.SDK_INT >= 15) {
                                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                intent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
                                intent.setData(Uri.fromParts("package", getActivity().getPackageName(), null));
                            }
                            startActivity(intent);

                        }
                    })
                    .create();
            alertDialog.show();
            alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).setTextColor(Color.BLACK);
            alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(Color.BLACK);
        }
    }


    @Override
    public void onClick(View v) {
        int vId = v.getId();
        if (vId == R.id.gover_cancel_tv) {
            recyclerViewExist.setVisibility(View.GONE);
            dataBinding.goverOverTv.setVisibility(View.GONE);
            dataBinding.goverHeadRl.setVisibility(View.VISIBLE);
            dataBinding.goverCancelTv.setVisibility(View.GONE);
            dataBinding.goverZwTv.setVisibility(View.VISIBLE);
//                dataBinding.backView.setVisibility(View.VISIBLE);
//                dataBinding.goverLinEdit.setVisibility(View.VISIBLE);
            mPresenter.getViewData();
            dataBinding.editViewLayout.setVisibility(View.GONE);
            dataBinding.titleLayout.bjTv.setVisibility(View.VISIBLE);
            //打开 下拉刷新
            dataBinding.goverSmartLayout.setEnableRefresh(true);
        } else if (vId == R.id.bj_tv) {
            String access_token = ACache.get(getActivity()).getAsString("access_token");
            if (access_token == null) {
                JumpUtils.jump(getActivity(), "login", 0);
                return;
            } else {
                dataBinding.editViewLayout.setVisibility(View.VISIBLE);
                recyclerViewExist.setVisibility(View.VISIBLE);
                for (int i = 0; i < allData.size(); i++) {
                    FunctionItem functionItem = allData.get(i);
//                    functionItem.setSelect(false);
//                        functionItem.setClick(false);
                    if (fiveheadList.contains(functionItem.getName())) {
                        allData.get(i).setClick(true);
                    } else {
                        allData.get(i).setClick(false);
                    }
                    functionAdapter.notifyDataSetChanged();
                }
                dataBinding.titleLayout.bjTv.setVisibility(View.INVISIBLE);
                dataBinding.goverOverTv.setVisibility(View.VISIBLE);
                dataBinding.goverHeadRl.setVisibility(View.GONE);
                dataBinding.goverCancelTv.setVisibility(View.VISIBLE);
                dataBinding.goverZwTv.setVisibility(View.GONE);
                //关闭下拉刷新
                dataBinding.goverSmartLayout.setEnableRefresh(false);
            }
        } else if (vId == R.id.setting_title) {
        } else if (vId == R.id.gover_over_tv) {//                if (recyclerViewExist.getVisibility() == View.VISIBLE) {
//                    recyclerViewExist.setVisibility(View.GONE);
//                } else {
//                    recyclerViewExist.setVisibility(View.VISIBLE);
//                }
            dataBinding.titleLayout.bjTv.setVisibility(View.VISIBLE);
            dataBinding.editViewLayout.setVisibility(View.GONE);
            recyclerViewExist.setVisibility(View.GONE);
            dataBinding.goverOverTv.setVisibility(View.GONE);
            dataBinding.goverHeadRl.setVisibility(View.VISIBLE);
            dataBinding.goverCancelTv.setVisibility(View.GONE);
            dataBinding.goverZwTv.setVisibility(View.VISIBLE);
//                dataBinding.backView.setVisibility(View.VISIBLE);
//                dataBinding.goverLinEdit.setVisibility(View.VISIBLE);
            mIdList.clear();
            for (int i = 0; i < allData.size(); i++) {
                FunctionItem functionItem = allData.get(i);
                functionItem.setSelect(true);
                functionAdapter.notifyDataSetChanged();
            }
            L.e(Constant.TAG, "我选中了几个+" + selData.size());
//                for (int i = 0; i < selData.size(); i++) {
//                    mIdList.add(selData.get(i).background);
//                    L.e(Constant.TAG, "所有id+" + selData.get(i).background);
//                }

            mIdList.clear();
            for (int i = 0; i < selData.size(); i++) {
                String name = selData.get(i).getName();
                L.e(Constant.TAG, "选中的应用" + selData.get(i).getName());
                for (int j = 0; j < class_list1.size(); j++) {
                    for (int k = 0; k < class_list1.get(j).getFunction_list().size(); k++) {
                        QueryAllFunctionNewRes.ClassListBean.FunctionListBean functionListBean = class_list1.get(j).getFunction_list().get(k);
                        if (functionListBean.getFunction_name() != null) {
                            if (functionListBean.getFunction_name().equals(name)) {
                                mIdList.add(functionListBean.getFunction_id() + "");
                            }
                        }
                    }
                }

            }
            ArrayList<String> strings = removeDuplicate(mIdList);

            StringBuffer id = new StringBuffer();
            for (int i = 0; i < strings.size(); i++) {
                id.append(strings.get(i)).append(",");
            }

            L.e(Constant.TAG, "拿到的地列表——" + id);
            mPresenter.changeUserFunc(id + "");
            //打开 下拉刷新
            dataBinding.goverSmartLayout.setEnableRefresh(true);
        }
    }
    @Subscribe(threadMode = ThreadMode.ASYNC)
    public void onMessageEvent(MessageEvent event) {
        if (event.getCode() == MessageEvent.CODE_EDIT_ALL) {
            {
                //点击编辑按钮
             //   dataBinding.titleLayout.bjTv.performClick();
            }
        }
    }
    @Override
    public void onDestroy(){
        EventBus.getDefault().unregister(this);
        super.onDestroy();
    }
    public void onCreate(Bundle bundle){
        EventBus.getDefault().register(this);
        super.onCreate(bundle);

    }

}
